#include "Teacher.h"
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

Teacher::Teacher(string id, string name, size_t age, vector<Klass *> klasses) : Person(id, name, age), klasses(klasses)
{
}

string toKlassesString(const vector<Klass *> &klasses)
{
    string result;
    for (const Klass *klass : klasses) {
        result = result + *klass + ",";
    }
    return result.substr(0, result.length() - 1);
}

string Teacher::Introduce()
{
    string result;
    result += Person::Introduce() + " I am a Teacher. I am teaching ";
    if(this->klasses.size() == 0) {
        result += "No Class.";
    } else {
        result += "Class " + toKlassesString(this->klasses) + ".";
    }
    return result;
}


string Teacher::IntroduceWith(Student &student){
    string result = this->BuildIntroduceBaseString(); 
    string teachingString = " I";
    if(this->IsTeach(student)){
        teachingString += " teach ";
    }else {
        teachingString += " don't teach ";
        
    }

    result += student.WithName([teachingString](string name) { 
        return teachingString + name + "."; 
    });

    return result;
}

bool Teacher::IsTeach(const Student &student){
    return any_of(this->klasses.begin(), this->klasses.end(), [student](Klass *klass){
        return student.IsIn(*klass);
    });
}

string Teacher::BuildIntroduceBaseString(){
    return Person::Introduce() + " I am a Teacher.";
}

void Teacher::notify(const Student &student) const
{
    cout << student.WithName([](string name) { return "I know " + name + "."; });
}
